<!DOCTYPE html>
<html>
<head>
    <title>经典标题</title>
    <#include "/header.html">
</head>
<body>
<style>
    th {
        text-align: center;
    }
</style>
<div>
    <div class="grid-btn">
        <div style="float: left">
            <input style="width: 100px" class="form-control" list="brandNameList" placeholder="品牌" id="brandNames">
            <datalist id="brandNameList" style="line-height: 10px">

            </datalist>
        </div>
        <a class="btn btn-default" onclick="reload()">查询</a>
    </div>
    <table id="jqGrid"></table>
    <div id="jqGridPager"></div>
</div>
</div>

<script>
    $(function () {
        $("#jqGrid").jqGrid({
            url: baseURL + 'sys/barticleinfo/queryList',
            datatype: "json",
            colModel: [
                {
                    label: '文章Id', name: 'id', index: 'id', align: "center", width: 60, key: true,
                    formatter: function (value, options, rowData) {
                        return "<a onclick=editInfo(" + value + ")>" + value + "</a>";
                    }
                },
                {
                    label: '文章名称', name: 'articleTitle', index: 'article_title', align: "center", width: 220,
                    formatter: function (value, options, rowData) {
                        var id = rowData['id'];
                        var del = rowData["articleStatus"];
                        var content = "";
                        if (del == 0) {
                            content = "<p style='color: red' >" + value + "</p>";
                        } else if (del == 2) {
                            content = "<p style='color: #8D8D8D'>" + value + "</p>";
                        } else {
                            content = "<p style='color: #009688'>" + value + "</p>";
                        }
                        return content;
                    }
                },
                {label: '品牌/分类', name: 'articleTypeName', index: 'articleTypeName', align: "center", width: 80},
                // //经典文章 0-是 1-否
                // {
                //     label: '经典文章',
                //     name: 'articleLevel',
                //     dataType: "int",
                //     sortable: true,
                //     index: 'article_level',
                //     align: "center",
                //     width: 50,
                //     formatter: function (value, options, rowData) {
                //         var content = "";
                //         if (value === 0) {
                //             content = '是';
                //         } else {
                //             content = '否';
                //         }
                //         return content;
                //     }
                // },
                // //经典标题 0-是 1-否
                // {
                //     label: '经典标题',
                //     name: 'htTemplateId',
                //     dataType: "int",
                //     sortable: true,
                //     index: 'ht_template_id',
                //     align: "center",
                //     width: 50,
                //     formatter: function (value, options, rowData) {
                //         var content = "";
                //         if (value === 0) {
                //             content = '是';
                //         } else {
                //             content = '否';
                //         }
                //         return content;
                //     }
                // },
                { label: '创建人', name: 'createUser', index: 'create_user', align: "center", width: 40},
                {
                    label: '来源', name: 'articleSource', index: 'article_source', align: "center", width: 40,
                    formatter: function (value, options, rowData) {
                        var thirdSource = rowData["thirdArticleSource"];
                        var source = rowData["articleSource"];
                        var content = "";
                        if (source == 1 && thirdSource == 1) {
                            content = "好文";
                        } else if (source == 1 && thirdSource == 2) {
                            content = "V名片"
                        } else if (source == 1 && thirdSource != null && thirdSource.length > 1) {
                            content = thirdSource;
                        } else if (value === 1) {
                            content = "平台";
                        } else if (value == 2) {
                            content = "用户";
                        } else if (value == 3) {
                            content = '用户'
                        } else if (value == 6) {
                            content = '入库'
                        }
                        return content;
                    }
                },
                {
                    label: '类型', name: 'resourceType', index: 'resource_type', align: "center", width: 40,
                    formatter: function (value, options, rowData) {
                        var articleTypeName = rowData["articleTypeName"];
                        var content = "";
                        if (value == 1) {
                            content = '文章';
                        } else if (value == 2) {
                            content = '视频';
                        }

                        if (articleTypeName == "" && value == 1) {
                            content = '早安打卡';
                        } else if (articleTypeName == "" && value == 2) {
                            content = '晚安打卡';
                        }
                        return content;
                    }
                },
                {
                    label: '状态', name: 'articleStatus', index: 'article_status', align: "center", width: 40,
                    formatter: function (value, options, rowData) {
                        var content = "";
                        if (value === 1) {
                            content = '正常';
                        } else if (value == 0) {
                            content = "<p style='color: red'>" + '删除' + "</>"
                        } else if (value == 2) {
                            content = '隐藏';
                        }
                        return content;
                    }
                },
                {
                    label: '热门',
                    name: 'articleRecommendStatus',
                    sortable: false,
                    index: 'articleRecommendStatus',
                    align: "center",
                    width: 40,
                    formatter: function (value, options, rowData) {
                        var content = "";
                        var id = rowData["id"];
                        if (value === 0 || value == "" || value == null) {
                            content = "<p style='text-align: center'>" + "否" + "</p>"
                        } else if (value == 1) {
                            content = "<p style='text-align: center'>" + "<strong style='color: red'>" + '是' + "</>" + "</p>";
                        }
                        return content;
                    }
                },
                {
                    label: '热度',
                    name: 'articleHotScore',
                    dataType: "int",
                    sortable: true,
                    index: 'article_hot_score',
                    align: "center",
                    width: 40
                    // ,
                    // formatter:function(value,options,rowData){
                    // 	return value;
                    // }
                },
                {
                    label: '分享',
                    name: 'articleShareCount',
                    dataType: "int",
                    sortable: true,
                    index: 'article_share_count',
                    align: "center",
                    width: 40
                },
                {
                    label: '查看',
                    name: 'articleOutReadCount',
                    dataType: "int",
                    sortable: true,
                    index: 'article_out_read_count',
                    align: "center",
                    width: 40
                }
            ],
            viewrecords: true,
            height: 520,
            rowNum: 15,
            rowList: [15, 30, 50],
            rownumbers: true,
            rownumWidth: 25,
            autowidth: true,
            multiselect: true,
            pager: "#jqGridPager",
            jsonReader: {
                root: "page.list",
                page: "page.currPage",
                total: "page.totalPage",
                records: "page.totalCount"
            },
            prmNames: {
                page: "page",
                rows: "limit",
                order: "order"
            },
            postData: {'articleTypeName': $("#brandNames").val(), 'htTemplateId': 0},
            gridComplete: function () {
                //隐藏grid底部滚动条
                $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
            }
        });
    })

    function editInfo(ids, event) {
        window.open("../sys/barticle_edit.html?id=" + ids);
    };

    function reload(event) {
        var page = 1;
        $("#jqGrid").jqGrid('setGridParam', {
            url: baseURL + 'sys/barticleinfo/queryList',
            postData: {'articleTypeName': $("#brandNames").val(), 'htTemplateId': 0},
            page: page
        }).trigger("reloadGrid");
    }

    setTimeout(function () {
        $.ajax({
            type: "POST",
            async: false,
            url: baseURL + 'sys/bbrandinfo/queryAll',
            contentType: "application/json",
            success: function (r) {
                // console.log(r);
                if (r.code == 0) {
                    for (var i = 0; i < r.brandInfo.length; i++) {
                        $("#brandNameList").append(
                            "<option value=" + r.brandInfo[i].brandName + ">" + "</option>");
                    }
                }
            }
        });
    }, 2000);
</script>
</body>
</html>
